package com.example.my_club2.welcome

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SPUtils
import com.example.my_club2.R
import com.therouter.TheRouter

class AdSwiperAdapter : RecyclerView.Adapter<AdSwiperAdapter.ViewHolder>() {
    private val images = listOf(
        R.drawable.home_swiper01,
        R.drawable.home_swiper02,
        R.drawable.home_swiper03
    )
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_ad_swiper, parent, false)
        return ViewHolder(view)
    }
    override fun getItemCount(): Int = images.size
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.image.setImageResource(images[position])
        if (position == 2) {
            holder.btnExperience.visibility = View.VISIBLE
        } else {
            holder.btnExperience.visibility = View.GONE
        }
        holder.btnExperience.setOnClickListener {
            SPUtils.getInstance().put("stare",2)
            SPUtils.getInstance().put("splashAgreement",true)
            TheRouter.build("app/MainActivity").navigation()
        }
    }
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val image: ImageView = view.findViewById(R.id.image)
        val btnExperience: TextView = view.findViewById(R.id.btn_experience)
    }
} 